package com.ghp.common.utils;


import com.ghp.common.exception.BusinessException;
import com.ghp.common.utils.response.ResponseStatus;
import org.springframework.stereotype.Controller;

/**
 * @author ghp
 * @title 异常工具类
 * @description
 */
@Controller
public class ThrowUtils {

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param businessException
     */
    public static void throwIf(boolean condition, BusinessException businessException) {
        if (condition) {
            throw businessException;
        }
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition        异常发生的条件
     * @param responseStatus 异常要响应的信息和状态码
     */
    public static void throwIf(boolean condition, ResponseStatus responseStatus) {
        throwIf(condition, new BusinessException(responseStatus));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition 异常发生的条件
     * @param message   错误信息
     */
    public static void throwIf(boolean condition, String message) {
        throwIf(condition, new BusinessException(message));
    }
}